<template>
  <nav>
    <van-tabbar v-model="active" active-color="#ee0a24" inactive-color="#000" @change="change" v-if='$route.meta.TabBarShow'>
      <van-tabbar-item icon="home-o" to="/home">首页</van-tabbar-item>
      <van-tabbar-item icon="bill-o" to="/order">点单</van-tabbar-item>
      <van-tabbar-item icon="cart-o" to="/theOrder">订单</van-tabbar-item>
      <van-tabbar-item icon="cart" to="/shopBag">购物车</van-tabbar-item>
      <van-tabbar-item icon="manager-o" to="/my">我的</van-tabbar-item>
    </van-tabbar>
  </nav>
  <router-view/>
</template>

<script>
export default {
  data(){
    return{
      active:0
    }
  },
  created() {
    this.active = JSON.parse(localStorage.getItem('active'))
  },
  methods:{
    change(active){
      localStorage.setItem('active',active)
    }
  },
  watch:{
    $route(){
      switch (this.$route.path){
        case '/home':
          this.active=0
              break
        case '/order':
          this.active=1
              break
        case '/theOrder':
          this.active=2
              break
        case '/shopBag':
          this.active=3
              break
        case '/my':
          this.active=4
              break
      }
    }
  }
}
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}

nav {
  padding: 10px;
}

nav a {
  font-weight: bold;
  color: #2c3e50;
}

nav a.router-link-exact-active {
  color: #42b983;
}
</style>
